﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MVCSpike
{
    public partial class CatViewOne : UserControl, ICatView
    {
        private readonly ChangeRequestEvents m_changeRequestedEvents;
        public CatViewOne()
        {
            InitializeComponent();
            m_changeRequestedEvents = new ChangeRequestEvents(this);
        }

        public void RegisterChangRequestListener<T>(string propertyName, EventHandler<PropertyChangeRequestEventArgs<T>> handler)
        {
            m_changeRequestedEvents.RegisterListener<T>(propertyName, handler);
        }

        public void UnRegisterChangRequestListener<T>(string propertyName, EventHandler<PropertyChangeRequestEventArgs<T>> handler)
        {
            m_changeRequestedEvents.UnRegisterListener<T>(propertyName, handler);             
        }

        [MvcProperty("Name")]
        public string CatName
        {
            set { lblName.Text = "Name: " + value; }
        }

        private int m_age = 0;
        [MvcProperty("Age")]
        public int CatAge
        {
            set 
            { 
                lblAge.Text = "Age: " + value;
                m_age = value;
            }
        }

        private void btn_Birthday_Click(object sender, EventArgs e)
        {
            m_changeRequestedEvents.Fire<Int32>("Age", m_age + 1);
        }
    }
}
